﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jumpton.SFA.Server.Entity;
using Jumpton.Persistent;
using Jumpton.Data;
using System.Data;

namespace Jumpton.SFA.Server.BusinessRule
{
    public class IcoProfileManager : BusinessLogic
    {
        public ICO_PROFILES Load(decimal headerID)
        {
            return (ICO_PROFILES)ObjectRow.Load(typeof(ICO_PROFILES), string.Format("this.ID='{0}'", headerID));
        }

        public ICO_PROFILES Load(string code, decimal domainID, decimal ID)
        {
            return (ICO_PROFILES)ObjectRow.Load(typeof(ICO_PROFILES), string.Format("this.CODE='{0}' and this.DOMAINID={1} and this.ID<>'{2}'", code, domainID, ID));
        }


        public static DataSet SearchCustomer(string strCondition)
        {
            return SqlData.OpenSP("usp_SelectCUSTOMERSsDynamicForOrder", strCondition);
        }

        /// <summary>
        /// 判断主键是否为新增或编辑
        /// </summary>
        /// <param name="orderHeader"></param>
        /// <returns></returns>
        public decimal Save(ICO_PROFILES orderHeader)
        {
            if (orderHeader != null)
            {
                try
                {
                    //判断是否存在
                    if (Load(orderHeader.CODE, orderHeader.DOMAIN_ID, orderHeader.ID) != null)
                    {
                        throw new Exception("名称已存在");
                    }
                 
                    
                    orderHeader.Save();
                }
                catch (Exception err)
                {
                    message = err.Message;throw err;
                }
                return orderHeader.ID;
            }
            return 0;
        }



        public static ObjectTable GetAllIcoProfileList(decimal domainID)
        {
            return new ObjectTable(typeof(ICO_PROFILES), "DOMAIN_ID=" + domainID);
        }

    }
}
